<?
	require_once "PHPUnit/Framework.php";
	
	# Facebook doesn't like user-agent: wget ;)
	define('USER_AGENT', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
	
	# Change these to your settings
	define('API_KEY', '00000000000000000000000000000000');
	define('FACEBOOK_USER', 'me@myself.com');
	define('FACEBOOK_PASSWORD', 'secret');

	class FacebookTestBase extends PHPUnit_Framework_TestCase
	{
		var $_cookie_jar = "/tmp/unittest.cookies.txt";

		/**
		 * Empty cookie jar, forcing each test to re-login to facebook
		 *
		 */
		function setUp()
		{
			@unlink($this->_cookie_jar);
		}

		/**
		 * Logs into the configured Facebook account
		 *
		 * Fails test if can't login (you are not here to debug Facebook's login page.)
		 */
		function loginFacebook()
		{
			exec("/usr/bin/wget -O - --user-agent='" . USER_AGENT . "' --save-cookies " . $this->_cookie_jar . " --keep-session-cookies --no-check-certificate http://login.facebook.com/login.php", $out1);
			exec("/usr/bin/wget -O - --user-agent='" . USER_AGENT . "' --load-cookies " . $this->_cookie_jar . " --save-cookies " . $this->_cookie_jar . " --keep-session-cookies --post-data='email=" . FACEBOOK_USER . "&pass=" . FACEBOOK_PASSWORD . "&version=1.0&api_key=" . API_KEY . "&login=Login' -p --no-check-certificate https://login.facebook.com/login.php", $out2);
			$this->assertTrue(!preg_match("/Sign up for Facebook/", join("", $out2)));
		}

		/**
		 * Fetch a url from Facebook using your logged in session
		 *
		 * @param $url 
		 * @return string content of page
		 */
		function fetchFacebook($url)
		{
			exec("/usr/bin/wget -O - --user-agent='" . USER_AGENT . "' --load-cookies " . $this->_cookie_jar . " --save-cookies " . $this->_cookie_jar . " --keep-session-cookies $url", $out);
			return join("", $out);
		}
	}
?>